﻿using Dynamicweb;
using Dynamicweb.Frontend;
using Dynamicweb.eCommerce;
using Dynamicweb.eCommerce.Products;
using Dynamicweb.eCommerce.Prices;
using Dynamicweb.eCommerce.International;

namespace DwProjectTemplate.CustomModules.Providers
{
	public class PriceProvider1 : PriceProvider
	{
		public override PriceRaw FindPrice( Product product, double quantity, string variantID, Currency currency, string unitID, Extranet user )
		{
			// Get the price from the DefaultPriceProvider
			// If you don't store prices in Dynamicweb eCommerce but in external tabels/databases/system
			// Disable the two lines below to save exec time, because they just come up with 0.0 for no use
			DefaultPriceProvider defaultProvider = new DefaultPriceProvider();
			PriceRaw rawPrice = defaultProvider.FindPrice( product, quantity, variantID, currency, unitID, user );

			if ( DwProjectTemplate.App.CodeSettings.EnablePriceProvider1 )
			{
				// HACK: Currently this catches all prices for SalesDiscounts, because
				// SalesDiscount generate OrderLines with a ProductID that equals an empty string
				// Read about a workaround: http://engage.dynamicweb-cms.com/Forum-5.aspx?action=ShowThread&ThreadID=2460

				if ( product.ID.Length <= 0 )
				{
					// Catch your SalesDiscount prices in here
				}
				else
				{
					// Do your ussual price calculations here
				}
			}

			//TODO: Add code here
			return rawPrice;
		}
	}
}
